<?php

/*
 * This file is the jQuery for the track document.
 * This handle the hide and show of informations in the track document.
 * 
 * Created by: Peter Agno Jr.
 * Date created: October 10, 2011
 */
?>

// Start - Change the color of the track circles if it was hovered and unhovered
function changeCircle(buttonId, theStepNum, theTotalStepNum, theColor, isHover) {
    var circleVersion = "4";

    // Prepare the hover
    if ( isHover == true ) {
        varHov = "hov";
    }
    else {
        varHov = "nothov";
    }

    // Prepare the variables
    if ( theStepNum  == 1 ) {
        // Prepare the position
        varPosition = "frst";
        varFolder = "first";
    }
    else if ( theStepNum == theTotalStepNum ) {
        // Prepare the position
        varPosition = "last";
        varFolder = "last";
    }
    else {
        // Prepare the position
        varPosition = "cntr";
        varFolder = "center";
    }

    jQuery("#"+buttonId).attr("src", "images/trackDoc/version"+circleVersion+"/"+varFolder+"/"+theColor+"_"+varHov+"_"+varPosition+".png");
} // End - Change the color of the track circles if it was hovered and unhovered

// START - JQUERUES FOR TRACKING
jQuery(".trackCircles").hover(
    function (mousePtr) {
        // START - DO THE FOLLOWING DURING HOVER
        buttonId = this.id;

        // MODIFY THE POSITION SO THAT IT IS NOT THAT FAR FROM THE CIRCLE
        topValue = mousePtr.pageY - 10;
        leftValue = mousePtr.pageX - 130;

        // MODIFY THE CSS POSITION BEFORE SHOWING
        jQuery(".trackInvisibleInfo").css({ 'display': 'none', 'top': topValue, 'left': leftValue });

        // CHECK FOR THE APPROPRIATE IMAGE
        tempSubstr = buttonId.split('__');
        theStepNum = tempSubstr[3];
        theTotalStepNum = tempSubstr[4];
        
        if ( tempSubstr[1] == "ylw" )
            changeCircle(buttonId, theStepNum, theTotalStepNum, "ylw", true);
        else {
            if ( tempSubstr[1] == "grn" ) 
                changeCircle(buttonId, theStepNum, theTotalStepNum, "grn", true);
            else
                changeCircle(buttonId, theStepNum, theTotalStepNum, "gry", true);
        }


        // START - AJAX THE NEEDED INFORMATIONS
        jQuery.ajax({
            type : 'POST',
            url : 'ajaxRequests/trackDocInfo.php',
            dataType : 'json',
            async : false,
            data: {
                documentId : tempSubstr[0],
                stepId : tempSubstr[2]
            },
            success : function(data){
                // SET THE INFORMATION IN THE DIV
                setInfo = "<table style='border:0; margin-bottom:0px;'>";
                setInfo += "<tr><td style='padding-left:0px; border:0;' class='trackTableTd'>Step Number : </td><td style='border:0;'>"+ tempSubstr[3]+"</td></tr>";

                if ( data.firstName != 'None' )
                    setInfo += "<tr><td style='padding-left:0px; border:0;' class='trackTableTd'>User : </td><td style='border:0;'>"+ data.firstName + data.middleName + data.lastName+"</td></tr>";

                setInfo += data.deptPos;

                // DISPLAY ROLE
//                            if ( data.firstName != 'None' )
//                                setInfo += "<tr><td style='padding-left:0px; border:0;' class='trackTableTd'>Role : </td><td style='border:0;'>"+ data.activity+"</td></tr>";

                setInfo += "</table>";
                // PUT THE INFORMATION IN THE DIV
                jQuery(".trackInvisibleInfo").html(setInfo);
                jQuery(".trackInvisibleInfo").show();
            },
            error : function() {
                alert("Error in getting the document information.");
            }
        }); // END - AJAX THE NEEDED INFORMATIONS
        // END - DO THE FOLLOWING DURING HOVER
    }, 
    function () {
        // START - DO THE FOLLOWING DURING NOT HOVER
        buttonId = this.id;

        // CHECK FOR THE APPROPRIATE IMAGE
        tempSubstr = buttonId.split('__');
        theStepNum = tempSubstr[3];
        theTotalStepNum = tempSubstr[4];
        
        if ( tempSubstr[1] == "ylw" )
           changeCircle(buttonId, theStepNum, theTotalStepNum, "ylw", false);
        else {
            if ( tempSubstr[1] == "grn" )
                changeCircle(buttonId, theStepNum, theTotalStepNum, "grn", false);
            else
                changeCircle(buttonId, theStepNum, theTotalStepNum, "gry", false);
        }


        jQuery(".trackInvisibleInfo").hide();
        // END - DO THE FOLLOWING DURING NOT HOVER
    }); // END - JQUERUES FOR TRACKING 